﻿<!DOCTYPE html>
<!--  window-icon 弹出框图 例: window-icon="http://www.qt6.com/favicon.ico"    -->
<html lang="en" window-frame="solid" window-icon="./view/icon/server-favicon.ico"></html>
<head>
	<meta charset="UTF-8">
	<title>popup</title>
    <link rel="stylesheet" type="text/css" href="./view/css/index.css">
</head>
<body id="body" role="window-caption">
    <div id="popup">
        <div class="addtaskmodetop skinbg" style="background-image: url(./view/img/boxbg.png);">
            <div class="title fl" >
                <img src="./view/img/logo_st.png" alt="" class="fl">
                <div class="titlename">
                    
                </div>
            </div>
            <button id="closewin" class="closewinicon topiconBg addmodeclosebtn" style="background-image: url(./view/img/topicon.png);"></button>
        </div>
        <div class="body"><span class="contentext"></span></div>
        <div class="operate">
            <div class="operatebox">
                
            </div>
        </div>
    </div>
    <script type="text/tiscript" src="./view/tiscript/index.tis"></script>
    <script type="text/tiscript" src="./view/tiscript/public.tis"></script>
    <script type="text/tiscript">
        self.ready = function() {
		    moveToScreenCenter(272,177);

            $(.titlename).text = view.parameters["title"]
            $(.contentext).text = view.parameters["text"]
           
            var operatehtml = ""
            if(view.parameters["type"] == "hint" || view.parameters["type"] == "systips" || view.parameters["type"] == "hintkey" || view.parameters["type"] == "delete" || view.parameters["type"] == "createface" || view.parameters["type"] == "downlod"   ){
                for (var (key,val) in view.parameters["buttons"]){
                    operatehtml += ` <button id="`+val.id+`" role="`+val.id+`">`+val.text+`</button>`
                }
            }
            $(.operatebox).html = operatehtml

          
            // 事件操作
            if(view.parameters["type"] == "hint"){
                $(#yes).on("click",function(){
                    view.load("http://10.1.2.200:9501",true)
                })
                $(#close).on("click",function(){
                    //关闭
                    view.close();
                })
            }
           
            // 事件操作
            if(view.parameters["type"] == "systips"){
                    $(#yeskey).on("click",function(){
                        if(view.parameters["url"]){
                       view.parameters["newin"].load(view.parameters["url"],true);
                       view.close();
                    }else{
                       view.close();
                    }
                });
            }
           

            if(view.parameters["type"] == "hintkey"){
                var ftype = view.parameters["ftype"]
                var newin = view.parameters["newin"]
                $(#closekey).on("click",function(){
                    //下载并移除
                    var folder = view.selectFolder("请选择下载目录","./" );
                    if(ftype && folder){
                        var downloadres = view.parameters["newin"].downloadkey(ftype,folder)

                        if (downloadres.success){
                            var removeres = view.parameters["newin"].removekey(ftype)  
                            if (removeres.success){
                                view.load("./view/privateSecret.html",true);
                                view.parameters["success"]("下载并移除成功",view.parameters["getsecretKey"])
                            }else{
                                view.parameters["error"](removeres.msg)
                            } 
                        }else{
                            view.parameters["error"](removeres.msg)
                        }  
                    } 
                    view.close();
                })
                

                $(#yeskey).on("click",function(){
                    //确认移除
                    var removeres = newin.removekey(ftype)   
                    if (removeres.success){ 
                        view.close();
                        view.parameters["success"]("移除成功",view.parameters["getsecretKey"])
                    }else{
                        view.parameters["error"](removeres.msg)
                    } 
                })
            }
            // 生成 密钥对
            if(view.parameters["type"] == "createface"){
                $(#closekey).on("click",function(){
                     view.close();
                })

                $(#yeskey).on("click",function(){
                   var res = view.parameters["newin"].generatersa()
                    if(res.success){
                        view.close();
                        view.parameters["success"]("生成成功，请将私钥妥善保管！！！！！",view.parameters["getsecretKey"])
                    }else{
                      view.parameters["error"](res.msg)
                    }
                    view.close();
                })
            }

            // 删除 
            if(view.parameters["type"] == "delete"){
                $(#yes).on("click",function(){
                    view.close();
                    var deleteuuid = view.parameters["deleteuuid"]
                    var deltask = view.parameters["newin"].deletetask(deleteuuid)
                    if(deltask.success){ 
                        view.close();
                        view.parameters["success"]("删除成功",view.parameters["fun"])
                    }else{
                        view.parameters["error"](deltask.msg)
                    }
                })
                $(#close).on("click",function(){
                    //关闭
                    view.close();
                })
            }
            var fun = function(){

            }
            // 下载 
            if(view.parameters["type"] == "downlod"){
                $(#yeskey).on("click",function(){
                    var folders = view.selectFolder("请选择下载目录","./" );
                    if(folders){
                        var folder = folders.split("//")[1]
                        var downloadobj = view.parameters["downloadobj"]
                        var resp = view.parameters["newin"].downloadfsfile(downloadobj,folder);
                        view.close();
                        var alertwin = view.parameters["alertwin"]
                        alertwin.close();
                        if(resp.success){
                            alertwin.parameters["success"]("下载成功",fun)
                        }else{
                            alertwin.parameters["error"](resp.msg)
                        }
                    }
                })
                $(#closekey).on("click",function(){
                    //关闭
                    view.close();
                })
            }
        }

       
    </script>
</body>
</html>